<?php

class Ext_Utils_Charset
{

    /**
     * Encodes from utf-8 to some character set
     *
     * @param string $utf8String
     * @param string $outEncoding
     * @return string $ret
     */
    public static function encodeString( $utf8String, $outEncoding )
    {
        $v = false;
        if ( function_exists( "iconv" ) ) {
            $v = iconv( 'UTF-8', $outEncoding, $utf8String );
        }
        if ( ! $v ) {
            return $utf8String;
        }
        return $v;
    }

    /**
     * Encodes from utf-8 to latin 1
     *
     * @param string $utf8String
     * @return string $latin1String
     */
    public static function encodeToLatin1( $utf8String )
    {
        return self::encodeString( $utf8String, 'ISO-8859-1' );
    }

    /**
     * Encodes from utf-8 to ascii
     *
     * @param string $utf8String
     * @return string $asciiString
     */
    public static function encodeToCP850( $utf8String )
    {
        return self::encodeString( $utf8String, 'CP850' );
    }

}
?>